package com.xoa.dev.pz.controller;



import com.xoa.model.users.Users;
import com.xoa.dev.pz.model.PzHouseRent;
import com.xoa.dev.pz.model.PzHouseWithBLOBs;

import com.xoa.dev.pz.service.PzHouseService;
import com.xoa.util.DateFormat;
import com.xoa.util.ToJson;
import com.xoa.util.common.session.SessionUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

@Controller
@RequestMapping("/sv1/pzhouse")
public class PzHouseController {
    @Resource

    private PzHouseService pzHouseService;

    /**
     * 增加
     * @param pzHouseWithBLOBs
     * @return
     */
    @ResponseBody
    @RequestMapping("/inserthouse")
    public ToJson insertHouse(PzHouseWithBLOBs pzHouseWithBLOBs, PzHouseRent pzHouseRent, HttpServletRequest request){
        Users user= SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users());
        pzHouseWithBLOBs.setCreateUser(user.getUserId());
        pzHouseWithBLOBs.setCreateTime(DateFormat.getDatestr(new Date()));
        pzHouseRent.setCreateUser(user.getUserId());
        pzHouseRent.setCreateTime(DateFormat.getDatestr(new Date()));
        pzHouseRent.setGridLocation(pzHouseWithBLOBs.getGridLocation());
        return pzHouseService.insertHouse(pzHouseWithBLOBs,pzHouseRent);
    }

    /**
     * 根据主键删除
     * @param houseId
     * @return
     */
    @ResponseBody
    @RequestMapping("/delhouse")
    public ToJson delHouse(int houseId){
        return pzHouseService.delHouse(houseId);
    }

    /**
     * 修改
     * @param pzHouseWithBLOBs
     * @return
     */
    @ResponseBody
    @RequestMapping("/uphouse")
    public ToJson upHouse(PzHouseWithBLOBs pzHouseWithBLOBs, PzHouseRent pzHouseRent, HttpServletRequest request){
        return pzHouseService.upHouse(pzHouseWithBLOBs,pzHouseRent,request);

    }

    /**
     * 查询
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/selecthouse")
    public ToJson selectHouse(Integer page, Integer pageSize, boolean useFlag, PzHouseWithBLOBs pzHouseWithBLOBs, @RequestParam(value="output", required = false,defaultValue = "0") int output, HttpServletResponse response, HttpServletRequest request){
        return pzHouseService.selectHouse(page,pageSize,useFlag,pzHouseWithBLOBs,output,response,request);


    }

    @ResponseBody
    @RequestMapping("/selectHouseByHouseId")
    public ToJson selectHouseByHouseId(HttpServletRequest request, Integer houseId){
        return pzHouseService.selectHouseByHouseId(request,houseId);
   }


  /*  *//**
     * 创建作者:   牛江丽
     * 创建日期:   2017年12月11日 下午16:02:00
     * 方法介绍:   房屋导入
     * 参数说明:
     * 返回值说明:
     *//*
    @ResponseBody
    @RequestMapping("/inputPzHouse")
    public  ToJson<PzHouseWithBLOBs> inputPzHouse(HttpServletRequest request, HttpServletResponse response, MultipartFile file, HttpSession session) {
        return pzHouseService.inputPzHouse(request,response,file,session);
    }*/
}
